#ifndef TIMER_H
#define TIMER_H

const unsigned int MaxNumberOfTimings = 10;

class TimingsList
{
public:

	TimingsList() { memset(m_timings, 0, sizeof(m_timings[0]) * MaxNumberOfTimings); m_last = 0; }

	__forceinline void addTiming(double t)
	{
		m_timings[m_last] = t;
		m_last = (m_last + 1) % MaxNumberOfTimings;
	}

	__forceinline double getTiming(unsigned char id) const { _ASSERT(id < MaxNumberOfTimings); return m_timings[id]; }

	double getAverage() const
	{
		double avr = 0;
		for (unsigned char i = 0; i < MaxNumberOfTimings; ++i)
			avr += m_timings[i];
		avr /= double(MaxNumberOfTimings);
		return avr;
	}

private:

	double m_timings[MaxNumberOfTimings];
	unsigned char m_last;

};

class Timer
{
public:

	__forceinline Timer()
	{
		LARGE_INTEGER fr;
		QueryPerformanceFrequency(&fr);
		m_freq = fr.QuadPart;
		reset();
	}

	__forceinline ~Timer() {}

	__forceinline double getTimeMiliseconds()
	{
		LARGE_INTEGER li;
		QueryPerformanceCounter(&li);
		return double(li.QuadPart - m_counterStart) / double(m_freq) * 1000.0;
	}

	__forceinline void reset()
	{
		LARGE_INTEGER li;
		QueryPerformanceCounter(&li);
		m_counterStart = li.QuadPart;
	}

private:

	__int64 m_freq;
	__int64 m_counterStart;

};

#endif TIMER_H